package com.hangzhou.xyj.ui.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.manager.IntentManager;
import com.hangzhou.xyj.model.UserModel;
import com.hangzhou.xyj.model.type.EIntentTagType;
import com.hangzhou.xyj.model.type.EUserType;
import com.hangzhou.xyj.ui.activity.ExpertInfoActivity;
import com.hangzhou.xyj.ui.activity.HomePageActivity;
import com.hangzhou.xyj.ui.adapter.base.BaseLoadingAdapter;
import com.hangzhou.xyj.ui.widget.CircleImageView;
import com.hangzhou.xyj.ui.widget.views.MyTextView;
import com.hangzhou.xyj.utils.PublicUtil;
import com.hangzhou.xyj.utils.constants.DataKey;

import java.util.List;

public class HisFocusAdapter extends BaseLoadingAdapter<UserModel> {
    public HisFocusAdapter(RecyclerView recyclerView, List<UserModel> list) {
        super(recyclerView, list);
    }

    @Override
    public ViewHolder onCreateNormalViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_myfocus_item, null);
        return new MyFocusViewHolder(view);
    }

    @Override
    public void onBindNormalViewHolder(ViewHolder holder, int position) {
        final UserModel userModel = mDataList.get(position);
        ((MyFocusViewHolder) holder).setData(userModel);
        final EUserType userType = PublicUtil.getUserType(userModel.getType(), userModel.getCheckFlag());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = null;
                switch (userType) {
                    case FAMOUS_EXPERT://名家
                        intent = new Intent(mContext, ExpertInfoActivity.class);
                        intent.putExtra(DataKey.INDEX, Integer.valueOf(userModel.getUserId()));
                        intent.putExtra(DataKey.TITLE, userModel.getNickName());
                        intent.putExtra(DataKey.INTENT_TAG, EIntentTagType.TAG_STAGE_EXPERT.getValue());
                        IntentManager.getInstance().goActivity(mContext, intent);
                        break;
                    case FAMOUS_TEAM://名团
                        intent = new Intent(mContext, ExpertInfoActivity.class);
                        intent.putExtra(DataKey.INDEX, Integer.valueOf(userModel.getUserId()));
                        intent.putExtra(DataKey.TITLE, userModel.getNickName());
                        intent.putExtra(DataKey.INTENT_TAG, EIntentTagType.TAG_STAGE_TEAM.getValue());
                        IntentManager.getInstance().goActivity(mContext, intent);
                        break;
                    default://其他
                        intent = new Intent(mContext, HomePageActivity.class);
                        intent.putExtra(DataKey.INDEX, Integer.valueOf(userModel.getFollowId()));
                        intent.putExtra(DataKey.TITLE, userModel.getNickName());
                        IntentManager.getInstance().goActivity(mContext, intent);
                        break;
                }
            }
        });
    }


    private class MyFocusViewHolder extends ViewHolder {
        MyTextView mTvName;
        MyTextView mTvSign;
        CircleImageView mCivHeader;

        private MyFocusViewHolder(View view) {
            super(view);
            mTvName = (MyTextView) view.findViewById(R.id.mtv_name);
            mTvSign = (MyTextView) view.findViewById(R.id.mtv_sign);
            mCivHeader = (CircleImageView) view.findViewById(R.id.civ_header);
        }

        public void setData(UserModel user) {
            mTvName.setText(user.getNickName());
            mTvSign.setText(user.getSignature());
            mCivHeader.displayImage(user.getHeadPic());
            //设置昵称右边的认证标志
            EUserType userType = user.getUserType();
            //设置昵称右边的认证标志
            mTvName.setCompoundDrawablesWithIntrinsicBounds(null, null, PublicUtil.getAuthenIconDrawable(mContext, userType), null);
        }
    }
}
